<template>
    <div>
      <el-container>
        <el-header class="homeHeader">
          <div class="title">云E办</div>
          <div>
            <el-button icon="el-icon-bell" type="text" size="normal" style="color: black;margin-right: 8px" @click="goChat" ></el-button>
            <el-dropdown class="userInfo" @command="handleCommand">
              <span class="el-dropdown-link">
                  {{user.name}}
<!--                <i><img :src="user.userFace"  /></i>-->
                <i><img :src="user.userFace" /></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="userCenter">个人中心</el-dropdown-item>
                <el-dropdown-item command="setting">设置</el-dropdown-item>
                <el-dropdown-item command="logout">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </el-header>
        <el-container>
          <el-aside width="200px">
            <el-menu router unique-opened>
              <el-submenu :index="index + ''" v-for="(item,index) in routes" :key="index" v-if="!item.hidden">
                <template slot="title">
                  <i :class="item.iconCls" style="color: #409eff;margin-right: 5px"></i>
                  <span>{{item.name}}</span>
                </template>
                  <el-menu-item :index="child.path" v-for="(child) in item.children">{{child.name}}</el-menu-item>
              </el-submenu>
            </el-menu>
          </el-aside>
          <el-main>
            <el-breadcrumb separator-class="el-icon-arrow-right" v-if="this.$router.currentRoute.path!='/home'">
              <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
              <el-breadcrumb-item>{{this.$router.currentRoute.name}}</el-breadcrumb-item>
            </el-breadcrumb>

            <div v-if="this.$router.currentRoute.path=='/home'" class="homeWelcome">
                欢迎来到云E办
            </div>
            <router-view class="homeRouteView"/>
          </el-main>
        </el-container>
      </el-container>
    </div>
</template>

<script>
export default {
  name: "Home",
  data() {
    return {
      user:JSON.parse(window.sessionStorage.getItem('user'))
    }
  },
  methods: {
    goChat() {
      this.$router.push("/chat");
    },
    handleCommand(command) {
        if (command == 'logout') {
          this.$confirm('此操作将退出登录, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            // 退出登录
              this.postRequest("/logout");

              // 清空sessionStorage
              window.sessionStorage.removeItem('token');
              window.sessionStorage.removeItem('user');
              // 清空store中菜单信息
              this.$store.commit('initRoutes',[]);

                // 跳转到登录页
            this.$router.replace('/');

          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消操作'
            });
          });
        }
    }
  },
  computed:{
      routes() {
        return this.$store.state.router;
      }
  }
}
</script>

<style scoped>
    .homeHeader {
      background-color: #409eff;
      display: flex;
      /*文字居中*/
      align-items: center;
      /*内容往两边分开*/
      justify-content: space-between;
      padding: 0 15px;
      box-sizing: border-box;
    }

    .homeHeader .title {
      font-size: 30px;
      color: #ffffff;
      font-family: 字魂167号-伊人黑;
    }

    .homeHeader .userInfo img {
      width: 48px;
      height: 48px;
      border-radius: 2em;
      margin-left: 8px;
    }
    .el-dropdown-link {
      /* 电脑鼠标边小手*/
      cursor: pointer;
    }


    .homeWelcome {
      font-size: 50px;
      font-family: 字魂167号-伊人黑;
      padding-top: 50px;
      color: #409eff;
      /*让文本居中*/
      text-align: center;
    }

    .homeRouteView {
      margin-top: 10px;
    }


</style>